﻿namespace Jsl.FxCop
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Microsoft.FxCop.Sdk;

    /// <summary>
    /// Maintains a unique collection of <see cref="Statement"/>s.
    /// </summary>
    public class UniqueStatementCollection : Collection<Statement>
    {
        #region Constructors
        /// <summary>
        /// Initializes a new instance of the <see cref="UniqueStatementCollection"/> class.
        /// </summary>
        public UniqueStatementCollection()
        {
        }
        #endregion Constructors

        #region Public Methods
        /// <summary>
        /// Adds the specified statements.
        /// </summary>
        /// <param name="statements">The statements to add.</param>
        public void Add(IEnumerable<Statement> statements)
        {
            foreach (var statement in statements)
            {
                this.Add(statement);
            }
        }
        #endregion Public Methods

        #region Protected Methods
        /// <summary>
        /// Inserts the item.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="item">The item.</param>
        protected override void InsertItem(int index, Statement item)
        {
            if (!this.Items.Contains(item))
            {
                this.Items.Add(item);
            }
        }
        #endregion Protected Methods
    }
}